import type { ParamsInterface, responseData } from "./interface";

// 统一封装基础的api
const baseUrl = 'https://m.maizuo.com/';
// 统一封装请求
const request = (params: ParamsInterface) => {
    return new Promise<responseData>((resolve, reject) => {
        uni.request({
            url: baseUrl + params?.url,
            data: params?.data || {},
            method: params?.method || "GET",
            header: params?.header,
            // 接口调用成功的回调函数
            success: (res) => {
                resolve(res.data as responseData);
            },
            // 接口调用失败的回调函数
            fail: (error) => {
                return reject(error);
            },
            // 成功和失败都会执行的回调
            complete(){}
        })
    })
}

export default request;